package st.business.tepth.business.user.busnumber.workholder.adapter;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import st.business.tepth.R;
import st.business.tepth.business.bean.DiagnoseBean;

/**
 * @author zhangyu
 * @date 2019/2/12
 */
public class TroubleDiagnoseAdapter extends BaseQuickAdapter<DiagnoseBean, BaseViewHolder> {
    private int mStatus;
    //故障id
    private int mPhenomenonId;
    private List<DiagnoseBean> mTempList;

    public TroubleDiagnoseAdapter(int layoutResId,
                                  int phenomenonId,
                                  int status, @Nullable List<DiagnoseBean> data) {
        super(layoutResId, data);
        mStatus = status;
        mPhenomenonId = phenomenonId;
    }

    public int getPhenomenonId() {
        return mPhenomenonId;
    }


    @Override
    protected void convert(BaseViewHolder helper, DiagnoseBean item) {
        helper.setText(R.id.tv_diagnose, item.getName());
        if (mStatus < 3) {
            helper.addOnClickListener(R.id.iv_diagnose_delete);
            helper.addOnClickListener(R.id.tv_add_program);
            helper.addOnClickListener(R.id.tv_relevance_program);
            if (item.isTemp()) {
                //临时添加的本地诊断不能添加方案
                helper.getView(R.id.tv_add_program).setVisibility(View.GONE);
                helper.getView(R.id.tv_relevance_program).setVisibility(View.GONE);
                helper.getView(R.id.iv_diagnose_delete).setVisibility(View.VISIBLE);
            } else {
                helper.getView(R.id.tv_add_program).setVisibility(View.VISIBLE);
                helper.getView(R.id.tv_relevance_program).setVisibility(View.VISIBLE);
                helper.getView(R.id.iv_diagnose_delete).setVisibility(View.VISIBLE);
            }
        } else {
            //已完成状态
            helper.getView(R.id.iv_diagnose_delete).setVisibility(View.GONE);
            helper.getView(R.id.tv_add_program).setVisibility(View.GONE);
            helper.getView(R.id.tv_relevance_program).setVisibility(View.GONE);
        }
    }

    public void setDataWhenDeleteSucceed(List<DiagnoseBean> list) {
        mTempList = list;
    }

    public void notifyAddData(List<DiagnoseBean> addList) {
        if (mTempList != null) {
            mTempList.addAll(0,addList);
            setNewData(mTempList);
        }
    }
}
